package com.macro.mall.controller;

import com.github.pagehelper.PageInfo;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.e.DataAnalysisPvEntDTO;
import com.macro.mall.dto.o.DataAnalysisPvOutDTO;
import com.macro.mall.service.DataAnalysisPvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

//

@RestController
@RequestMapping("/dataAnalysis/pv")
public class DataAnalysisPvController {
    @Autowired
    private DataAnalysisPvService dataAnalysisPvService;

    /*@RequestMapping("/list")
    public CommonResult list(@RequestBody DataAnalysisPvEntDTO dataAnalysisPvEntDTO) throws ParseException {
//        if (dataAnalysisPvEntDTO.getBeginTimeStr()!=null &&dataAnalysisPvEntDTO.getBeginTimeStr()!=""){
//            dataAnalysisPvEntDTO.setBeginTime(DateUtils.parseDate(dataAnalysisPvEntDTO.getBeginTimeStr(),"yyyy-MM-dd HH:mm:ss"));
//        }
//        if (dataAnalysisPvEntDTO.getEndTimeStr()!=null&& dataAnalysisPvEntDTO.getEndTimeStr()!=""){
//            dataAnalysisPvEntDTO.setEndTime(DateUtils.parseDate(dataAnalysisPvEntDTO.getEndTimeStr(),"yyyy-MM-dd HH:mm:ss"));
//        }
        PageInfo<DataAnalysisPvOutDTO> list = dataAnalysisPvService.list(dataAnalysisPvEntDTO);
        return CommonResult.success(list);
    }*/

    @RequestMapping("/list")
    public CommonResult list(@RequestBody DataAnalysisPvEntDTO dataAnalysisPvEntDTO) throws ParseException {
        PageInfo<DataAnalysisPvOutDTO> list = dataAnalysisPvService.list(dataAnalysisPvEntDTO);
        return CommonResult.success(list);
    }

    @RequestMapping("/get")
    public CommonResult get(@RequestBody DataAnalysisPvEntDTO dataAnalysisPvEntDTO){
        return null;
    }

    @RequestMapping("/modify")
    public CommonResult modify(@RequestBody DataAnalysisPvEntDTO dataAnalysisPvEntDTO){
        int modify = dataAnalysisPvService.modify(dataAnalysisPvEntDTO);
        CommonResult<Object> commonResult = new CommonResult<>();
        if (modify>0){
            commonResult.setCode(200);
            commonResult.setMessage("操作成功！");
        }else {
            commonResult.setCode(500);
            commonResult.setMessage("操作失败！");
        }
        return commonResult;
    }

    @RequestMapping("/setStatus")
    public CommonResult setStatus(@RequestBody DataAnalysisPvEntDTO dataAnalysisPvEntDTO){
        int modify = dataAnalysisPvService.modify(dataAnalysisPvEntDTO);
        CommonResult<Object> commonResult = new CommonResult<>();
        if (modify>0){
            commonResult.setCode(200);
            commonResult.setMessage("操作成功！");
        }else {
            commonResult.setCode(500);
            commonResult.setMessage("操作失败！");
        }
        return commonResult;
    }

    @RequestMapping("/setOff")
    public CommonResult setOff(@RequestBody DataAnalysisPvEntDTO dataAnalysisPvEntDTO){
        return null;
    }
}
